package com.shine.app.ui;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shine.app.R;
import com.shine.app.commons.Calendars;
import com.shine.app.widget.rangebar.RangeBar;
import com.shine.app.widget.rangebar.RangeBar.OnRangeBarChangeListener;

public class RangeBarActivity extends PlayerActivity {

	protected RangeBar rangebar;
	protected TextView starTextView;
	protected TextView endTextView;
	protected TextView timeTextView;
	protected LinearLayout layout_time;
	protected LinearLayout search_time;
	protected ImageView search_time_imageView;
	protected Calendars instance;

	protected void initRangeView() {
		instance = Calendars.getInstance();
		search_time = (LinearLayout) this.findViewById(R.id.search_time);
		layout_time = (LinearLayout) this.findViewById(R.id.layout_time);
		search_time_imageView = (ImageView) this
				.findViewById(R.id.search_time_image);
		search_time_imageView.setTag(false);

		starTextView = (TextView) findViewById(R.id.text_starttime);
		endTextView = (TextView) findViewById(R.id.text_endtime);
		timeTextView = (TextView) findViewById(R.id.text_time);
		rangebar = (RangeBar) findViewById(R.id.rangebar);
		rangebar.setOnRangeBarChangeListener(new RangeBarOnTouch());
		initRangeBarParam();
	}

	protected void initRangeBarParam() {
		rangebar.setTickCount(13);
		rangebar.setLeftIndex(0);
		rangebar.setRightIndex(12);
		starTextView.setText(instance.getRangebarTime(rangebar.getLeftIndex()));
		endTextView.setText(instance.getRangebarTime(rangebar.getRightIndex()));
	}

	public class RangeBarOnTouch implements OnRangeBarChangeListener {

		@Override
		public void onIndexChangeListener(RangeBar rangeBar,
				int leftThumbIndex, int rightThumbIndex) {
			starTextView.setText(instance.getRangebarTime(leftThumbIndex));
			endTextView.setText(instance.getRangebarTime(rightThumbIndex));
			timeTextView.setVisibility(View.VISIBLE);
		}
	}
}
